<?php

include 'grocery_crud.php';

class ExCRUD extends grocery_CRUD {

    private $CI;

    public function __construct() {
        parent::__construct();
        $this->CI = & get_instance();
        
    }

    public function set_add($set) {
        $this->unset_add = $this->getBool($set);
    }

    public function set_edit($set) {
        $this->unset_edit = $this->getBool($set);
    }

    public function set_delete($set) {
        $this->unset_delete = $this->getBool($set);
    }

    public function standartCheck() {
        $ci = & get_instance();
        $ci->load->library("session");
        if (($ci->session->userdata("id_member") == "") || ($ci->session->userdata("id_member") == null)) {
            echo "<script>alert('Silahkan untuk login terlebih dahulu !');</script>";
            header("location:".site_url("/"));
        }
    }

    function getBool($set) {
        if ($set == 'true') {
            return false;
        } else {
            return true;
        }
    }

    function getURL() {
        $pageURL = 'http';
        if ($_SERVER["HTTPS"] == "on") {
            $pageURL .= "s";
        }
        $pageURL .= "://";
        if ($_SERVER["SERVER_PORT"] != "80") {
            $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
        } else {
            $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
        }
        return $pageURL = $_SERVER["REQUEST_URI"];
    }

    function extractURL($value) {
        $data = explode('/', (trim($_SERVER["REQUEST_URI"], "#")));
        $hasil = '/' . $data[3] . '/' . $data[4];
        return $hasil;
    }
    
    function getRemoveLastIndexURL($value){
        $data = explode('/', (trim($_SERVER["REQUEST_URI"], "#")));
        $hasil='';
        for($i=0; $i<count($data)-1; $i++){
           $hasil.='/'.$data[$i]; 
        }
        return $hasil;
    }

    function get_scalar($query, $field_name)
    {
        $result = $this->db->query($query);

        if ($result->num_rows() > 0)
        {
            $row = $result->row();
            return $row->$field_name;
        }
        else
        {
            return false;
        }
    }
    
    function non($data) {
        $data = str_replace("Rp. ", "", $data);
        $data = str_replace("Rp.", "", $data);
        $data = str_replace(".00", "", $data);
        $data = str_replace(",", "", $data);
        return $data;
}
}

?>
